#============================================================
#	Override Check Box
#============================================================
# @datetime: 2022-1-29 17:53:04
#============================================================

tool
extends HBoxContainer


var editor_interface : EditorInterface
var data setget set_data


onready var check_box = $CheckBox
onready var keyword_label = $KeyWord
onready var function_label = $Function
onready var type_label = $Type
onready var args_label = $Args


#==================================================
#   Set/Get
#==================================================
func set_editor_interface(value: EditorInterface):
	editor_interface = value
	
	if not self.is_inside_tree():
		yield(self, "ready")
	
	# 获取配色颜色
	var se = editor_interface.get_editor_settings()
	var h = "text_editor/highlighting"
	
	keyword_label.modulate = se.get_setting(h + "/keyword_color")
	function_label.modulate = se.get_setting(h + "/function_color")
	type_label.modulate = se.get_setting(h + "/base_type_color")
	
	# 连接信号
	if not is_connected("gui_input", self, "_on_click"):
		self.connect("gui_input", self, "_on_click")


func is_pressed() -> bool:
	return check_box.pressed


func set_data(value: Dictionary):
	data = value
	if data == null:
		return
	if function_label == null:
		yield(self, "ready")
	
	# 方法名
	function_label.text = data['name']
	
	# 参数
	var args : String = ""
	for i in data['args']:
		args += i['name'] + ", "
	args = args.strip_edges().trim_suffix(",")
	args_label.text = "(" + args + "): "
	
	# 返回类型
	type_label.text = data['return']


#============================================================
#   连接信号
#============================================================
func _on_click(event):
	if event is InputEventMouseButton:
		if event.button_index == BUTTON_LEFT and event.pressed:
			check_box.pressed = not check_box.pressed

